package com.example.administrator.puzzlepic.com.xiaoxu.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;

import java.io.File;

/**
 * Created by Administrator on 2016/4/6.
 */
public class GetPicUtil {

    private static final int RESULT_IMAGE = 100;
    //图片类型
    private static final String IMAGE_TYPE = "image/*";

    //照片的路径
    public static String TEMP_IMAGE_PATH =  Environment.getExternalStorageDirectory().getPath() + "/temp.png";
    //返回码：相机
    private static final int RESULT_CAMERA = 200;

    public static void getNativePic(Activity activity){

        //本地图库
        Intent intent = new Intent(Intent.ACTION_PICK,null);//从列表中选择某项并返回所选数据
        intent.setDataAndType(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,IMAGE_TYPE);

        activity.startActivityForResult(intent,RESULT_IMAGE);
    }
        //拍照

    public static void takePhoto(Activity activity){

        //系统相机
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

        Uri photoUri = Uri.fromFile(new File(TEMP_IMAGE_PATH));

        intent.putExtra(MediaStore.EXTRA_OUTPUT,photoUri);

        activity.startActivityForResult(intent,RESULT_CAMERA);

    }



}
